import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams, UploadFile } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { fail } from 'assert';
const globSetting = useGlobSetting();
const { uploadUrl = '' } = useGlobSetting();
import axios from 'axios';

/**
 * @description: Upload interface
 */
export function uploadApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: uploadUrl,
      onUploadProgress,
    },
    params,
  );
}

export function uploadImage(file) {
  const params: UploadFileParams = {
    name: 'formFile',
    file,
  };
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${globSetting.apiBaseUrl}${globSetting.apiUrl}/images/upload`,
      onUploadProgress: () => {},
    },
    params,
  );
}
// 上传阳台的图片
export function uploadImageYt(file) {
  const params: UploadFileParams = {
    name: 'file',
    file,
  };
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${globSetting.apiBaseUrl}${globSetting.apiUrl}/images/uploadfile_yt`,
      onUploadProgress: () => {},
    },
    params,
  );
}

export function uploadApkApi(values) {
  const params: UploadFileParams = {
    name: 'file',
    file: values.file[0],
    data: {
      necessaryUpdate: values.necessaryUpdate,
      changelog: values.changelog,
    },
  };
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${globSetting.apiBaseUrl}${globSetting.apiUrl}/admin/app/upload`,
      onUploadProgress: () => {},
    },
    params,
  );
}

export function uploadfileApi(values) {
  const params: UploadFileParams = {
    file: values.file[0],
    data: {
      id: values.id,
    },
  };
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: `${globSetting.apiBaseUrl}${globSetting.apiUrl}/images/uploadfile`,
      onUploadProgress: () => {},
    },
    params,
  );
}
